class MyBinaryInteger implements Comparable
{
	public final int n;
	
	public MyBinaryInteger(int x)
	{
		n = x;
	}
	
	private int count()
	{
		int x=n, ct=0;
		
		//TERRIBLE IMPLEMENTATION
		/*while (x != 0)
		{
			if (x%2 == 1) ct++;
			x /= 2;
		}*/
		
		//optimized version
		while (x != 0)
		{
			if ((x & 1) == 1) ct++;
			x >>= 1;
		}
		return ct;
	}
	
	public int compareTo(Object y)
	{
		int xCt=count(), yCt=((MyBinaryInteger)y).count();
		if (xCt<yCt)
			return -1; //lower than
		else if (xCt>yCt)
			return 1; //same as
		else
			return 0; //more than
	}
	
	public String toString()
	{
		return String.valueOf(n)+" ("+Integer.toString(n, 2)+")";
	}
	
	public static void main(String[] args)
	{
		MyBinaryInteger mb1 = new MyBinaryInteger(10); //2
		MyBinaryInteger mb2 = new MyBinaryInteger(65537); //2
		System.out.println(mb1.compareTo(mb2)); //0
		System.out.println(mb2.compareTo(mb1)); //0
		MyBinaryInteger mb3 = new MyBinaryInteger(255); //7
		System.out.println(mb1.compareTo(mb3)); //-1
	}
}
